<template>
	<view>
		<uni-search-bar @input="search" placeholder="搜索任务" bgColor="#fff" />
		<view class="list-main">
			<view class="flex align tabs">
				<view :class="act==1?'act':''" @click="toAct(1)">探店任务</view>
				<view :class="act==2?'act':''" @click="toAct(2)">短视频任务</view>
			</view>
			<view class="cards">
				<view class="card-select flex align between">
					<view :class="act2==0?'act':''" @click="toAct2(0)">待选号</view>
					<view :class="act2==1?'act':''" @click="toAct2(1)">已选中</view>
					<view :class="act2==2?'act':''" @click="toAct2(2)">未选中</view>
				</view>
				<view :url="'/pages/task/info?id='+item.task_id+'&type='+act+'&typeMine=2'" hover-class="none"
					class="list" v-for="(item,index) in list" :key="index">
					<view class="list-info1 flex between" @click="toUrl('/pages/task/info?id='+item.id+'&type='+act+'&typeMine=2')">
						<image :src="item.task.store_text[0].logo"></image>
						<view class="info1-info" style="width: 52%;">
							<view>{{item.task_name}}</view>
							<view v-if="act==1">探店日期：{{item.task.other.visit_store.dates[0]}}</view>
							<view v-if="act==1">接待人数：{{item.task.other.visit_store.day_person_limit}}</view>
							<view>截止日期：{{item.task.deadline_time}}</view>
							<view>粉丝数量：{{item.task.fans}}人</view>
						</view>
						<view style="width: 23%;" class="price" v-if="item.task.level_text!=0">{{item.task.level_text}}</view>
						<view v-else style="width: 23%;"></view>
						<!-- <view class="price">{{item.task.cost_amount}}￥</view> -->
					</view>
					<view class="list-info2 flex align between">
						<view class="tags flex align">
							<text>{{item.task.cost_type_text}}</text>
							<text>{{item.task.app_text}}任务</text>
							<text v-if="item.task.region_limit!=''">地区限制：{{item.task.region_limit}}</text>
							<!-- <text>粉丝数量：{{item.fans}}人</text> -->
						<!-- 	<text v-for="(item2,index2) in item.task.signing_condition_text"
								:key="index2">{{item2}}</text> -->
						</view>
						<view class="nums">
							招募{{item.task.num}}人 /剩余{{item.task.remain_num}}人
						</view>
					</view>
					<view class="time">申请时间：{{item.create_time}}</view>
					<view class="flex align btns-item">
						<view class="btns" @click="toUrl('/pages/task/submitList?id='+item.task_id)" v-if="item.status==1&&item.last_submit!=null">提交列表</view>
						<view v-if="item.last_submit==null">
							<view class="btns" @click="toUrl('/pages/task/submit?id='+item.task_id +'&praise_screenshot='+item.task.praise_screenshot)" v-if="item.status==1">提交任务</view>
						</view>
						<view v-else>
							<view class="btns" @click="toUrl('/pages/task/submit?id='+item.task_id +'&praise_screenshot='+item.task.praise_screenshot)" v-if="item.status==1&&item.last_submit.check_status=='3'">提交任务</view>
							<view class="btns" style="background: green;" v-if="item.status==1&&item.last_submit.check_status=='2'">任务已完成</view>
						</view>
						
					</view>
				</view>
				<uni-load-more :status="status" v-if="!empty" :content-text="loadText"></uni-load-more>
				<xw-empty :isShow="empty" text="暂无数据" textColor="#777777"></xw-empty>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		taskApplyLists
	} from '@/api/apiData.js';
	export default {
		data() {
			return {
				name: '',
				act: 1,
				act2: 0,
				totalPage: 1,
				page: 0,
				offset: 10,
				list: [],
				scrollTop: 0,
				empty: false,
				loadText: {
					loadmore: '点击或上拉加载更多',
					loading: '努力加载中',
					nomore: '实在没有了'
				},
				status: 'loadmore',
			};
		},
		onLoad() {
			this.getlist();
		},
		onPageScroll(e) {
			const that = this;
			that.scrollTop = e.scrollTop;
		},
		onReachBottom() {
			const that = this;
			that.getlist();
		},
		methods: {
			toUrl(u){
				uni.navigateTo({
					url:u
				})
			},
			search(e) {
				this.name = e,
					this.page = 0
				this.list = []
				this.getlist();
			},
			toAct(a) {
				this.act = a
				this.page = 0
				this.list = []
				this.getlist();
			},
			toAct2(a) {
				this.act2 = a
				this.page = 0
				this.list = []
				this.getlist();
			},
			async getlist() {
				const that = this;
				const {
					totalPage,
					page,
					offset,
					list,
					act,
					name,
					act2
					// channel_id,
				} = that;
				
				let obj = {
					size: offset,
					page: page + 1,
					task_type: act == 1 ? 2 : 1,
					title: name,
					status: act2.toString()
					// channel_id: channel_id
				};
				// if(obj.task_type==1){
				// 	obj.status = ''
				// }
				that.status = 'loading';
				if (totalPage > page) {
					let result = await taskApplyLists(obj);
					if (result.code == 1) {
						that.page = page + 1;
						if (result.data.total == 0) {
							console.log((888))
							that.empty = true;
							that.status = 'nomore';
							return;
						}
						that.empty = false;
						setTimeout(() => {
							that.status = 'loadmore';
						}, 500);
						that.list = list.concat(result.data.list);
						that.totalPage = Math.ceil(result.data.total / offset);
					}
				} else {
					setTimeout(() => {
						that.status = 'nomore';
					}, 500);
				}
			},
		},
	}
</script>

<style lang="scss" scoped>
	.list-main {
		margin: 20rpx;

		.tabs {
			font-size: 32rpx;
			font-weight: bold;

			view {
				margin-right: 18rpx;
				position: relative;
				padding: 10rpx 0;
			}

			.act::after {
				content: "";
				position: absolute;
				bottom: 0;
				width: 50%;
				left: 25%;
				height: 9rpx;
				background: #FF6543;
				border-radius: 5rpx;
			}
		}

		.cards {
			background: white;
			border-radius: 10rpx;
			box-shadow: 1rpx 1rpx 1rpx 4rpx #e8e8e8;
			margin-top: 20rpx;

			.card-select {
				font-weight: bold;
				font-size: 28rpx;
				padding: 12rpx 53rpx;
				border-bottom: solid 1rpx gainsboro;

				.act {
					color: #FF6543;
				}
			}

			.list {
				margin: 16rpx;
				border-bottom: solid 1rpx gainsboro;
				padding-bottom: 23rpx;

				.time {
					font-size: 25rpx;
					margin-top: 20rpx;
					text-align: right;
					color: grey;
					font-weight: bold;
				}

				.list-info1 {
					padding: 30rpx;

					image {
						width: 138rpx;
						height: 138rpx;
						border-radius: 12rpx;
					}

					.info1-info {
						margin-left: 24rpx;
						color: #AAAAAA;
						font-size: 18rpx;

						view:nth-child(1) {
							    font-size: 38rpx;
							    font-weight: bold;
							    color: black;
							    margin-bottom: 10rpx;
						}
					}

					.price {
						color: #FF6543;
						font-size: 30rpx;
						font-weight: bold;
					}
				}

				.list-info2 {
					.tags {
						color: #FF6543;
						font-size: 18rpx;

						text {
							border: solid 1rpx;
							padding: 2rpx 16rpx;
							border-radius: 6rpx;
							margin-right: 12rpx;
						}
					}

					.nums {
						color: #FF6543;
						font-size: 24rpx;
						font-weight: bold;
					}
				}
			}
		}

		.btns-item {
			justify-content: flex-end;
			.btns {
				background: #FF6543;
				color: white;
				width: fit-content;
				margin-top: 20rpx;
				padding: 5rpx 20rpx;
				font-size: 28rpx;
				border-radius: 10rpx;
				margin-left: 30rpx;
			}
		}

	}
</style>